package com.ncmmall.mall.controller.securitys;

import com.ncmmall.mall.controller.securitys.shiro.Securitys;
import com.ncmmall.domain.security.nav.Navigation;
import com.ncmmall.querychannel.service.QueryChannelService;
import com.google.common.collect.ImmutableMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * @author tongchun
 *         工作台
 */
@Controller
public class DashboardController {

    @Autowired
    private QueryChannelService queryChannelService;


    @Value("${web.domain}")
    private String webDomain;

    /**
     * 后台布局
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/dashboard", method = RequestMethod.GET)
    private String dashboard(Model model) {
        List<Navigation> result = queryChannelService.findAll("select n from Navigation n where n.role.id =:id and n.parent is null order by n.rank desc ", ImmutableMap.of("id", Securitys.currentUser().getRole().getId()), Navigation.class);
        model.addAttribute("navigation", result);

        return "securitys/dashboard";
    }

    /**
     * 工作台页面
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/main", method = RequestMethod.GET)
    private String index(Model model) {
        return "securitys/main";
    }

}
